package com.jiu345.api.controller;

import com.jiu345.api.pojo.GoodsCategory;
import com.jiu345.api.pojo.vo.CategoryVo;
import com.jiu345.api.service.IGoodsCateService;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * package:GoodsCateController
 * @author MrLei QQ:235921049
 * @date 2024-05-21
 * desc:商品分类
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/goods/category")
public class GoodsCateController extends BaseController {
    private final IGoodsCateService cateService;


    /*商品分类*/
    @GetMapping("/list")
    public R<List<GoodsCategory>> list(GoodsCategory bo){
        List<GoodsCategory> list = cateService.queryList(bo);
        return R.ok(list);
    }
    /*根据一级分类查询二级*/
    @GetMapping("/list/{id}")
        public R<List<GoodsCategory>> twoList(@NotNull(message = "主键不能为空")
                                              @PathVariable Long id){
        List<GoodsCategory> list = cateService.selectTwoList(id);
        return R.ok(list);
    }
    /*分类详情*/
    @GetMapping("/{id}")
    public R<GoodsCategory> getInfo(@NotNull(message = "主键不能为空")
                                        @PathVariable Long id) {
        return R.ok(cateService.queryById(id));
    }
    /*二级分类详情*/
    @GetMapping("/sub/{id}")
    public R<GoodsCategory> getTwoInfo(@NotNull(message = "主键不能为空")
                                    @PathVariable Long id) {
        return R.ok(cateService.queryByTwoId(id));
    }
    /*获取父级分类ID*/
    @GetMapping("/parent/{id}")
    public R<CategoryVo> getParent(@NotNull(message = "主键不能为空")
                                    @PathVariable Long id) {
        return R.ok(cateService.selectParentId(id));
    }


}
